package a05_双指针法;

/**
 * <p>
 * a01_移除元素
 * </p>
 *
 * @author flyduck
 * @since 2024-07-16
 */
public class a01_移除元素 {
    public static int removeElement(int[] nums, int val) {
        int slowIndex = 0;
        int fastIndex = 0;
        while (fastIndex < nums.length) {
            if(nums[fastIndex] != val){
                nums[slowIndex] = nums[fastIndex];
                slowIndex++;
                fastIndex++;
            }else {
                fastIndex++;
            }
        }
        return slowIndex;
    }
}
